package com.wolfeyes.framework.web.context;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @title Servlet容器上下文环境的操作工具类
 * @className WebContextUtils
 * @author yanyljava
 * @create 2022-01-14 21:25
 */
public class WebContextUtils {

	private static ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal();
	
	private static ThreadLocal<HttpServletResponse> responseHolder = new ThreadLocal();

	private WebContextUtils() {
		
	}

	public static void init(HttpServletRequest request, HttpServletResponse response) {
		requestHolder.set(request);
		responseHolder.set(response);
	}

	public static void destroy() {
		requestHolder.remove();
		responseHolder.remove();
	}

	public static HttpServletRequest getRequest() {
		return requestHolder.get();
	}

	public static HttpServletResponse getResponse() {
		return responseHolder.get();
	}
	
}

